<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%@include file="../header.jsp" %>
<script>
	$(function(){
		bindProvider()
		bindEvent();
	})
		
	//绑定供应商下拉列表
	function bindProvider(){
		$.post("listProvider",function(msg){
			var str = "";
			$(msg).each(function(i){
				var p = msg[i]
				str += "<option value='"+p.id+"'>"
				str += p.proname
				str += "</option>"
			})
			$("#providerId").append(str)
		},"json")
		
		
	}

	function bindEvent(){
		$("#add").click(function(){
			//数据校验
			var billcode = $("#billcode").val();
			if(billcode == null || billcode == ""){
				alert("请输入订单编号")
				return;
			}
			var productname = $("#productname").val();
			if(productname == null || productname == ""){
				alert("请输入商品名")
				return;
			}
			var productunit = $("#productunit").val();
			if(productunit == null || productunit == ""){
				alert("请输入商品单价")
				return;
			}
			if(isNaN(productunit)){
				alert("请正确输入商品单价")
				return;
			}
			if(Number(productunit)  <= 0){
				alert("请正确输入商品单价")
				return;
			}
			document.forms[0].submit();
		})
		
	}
</script>

<c:if test="${requestScope.insertFlag > 0 }">
	<script>
		alert("添加成功")
		window.location = "toBillList"
	</script>	
</c:if>
<c:if test="${requestScope.insertFlag == 0 }">
	<script>
		alert("添加失败")
	</script>
</c:if>

	<div class="right">
     <div class="location">
         <strong>你现在所在的位置是:</strong>
         <span>订单管理页面 >> 订单添加页面</span>
     </div>
     <div class="providerAdd">
         <form  method="post" action="insertBill">
             <!--div的class 为error是验证错误，ok是验证成功-->
             <div class="">
                 <label for="billCode">订单编码：</label>
                 <input type="text"  class="text" id="billcode" name="billcode"  value=""> 
				 <!-- 放置提示信息 -->
				 <font color="red"></font>
             </div>
             <div>
                 <label for="productName">商品名称：</label>
                 <input type="text" id="productname" name="productname" value=""> 
				 <font color="red"></font>
             </div>
             <div>
                 <label for="productUnit">商品单价：</label>
                 <input type="text" id="productunit" name="productunit" value=""> 
				 <font color="red"></font>
             </div>
             <div>
                 <label for="productCount">商品数量：</label>
                 <input type="text" name="productcount"  value=""> 
				 <font color="red"></font>
             </div>
             <div>
                 <label for="totalPrice">总金额：</label>
                 <input type="text" name="totalprice"  value=""> 
				 <font color="red"></font>
             </div>
             <div>
                 <label >供应商：</label>
                 <select name="provider.id" id="providerId">
		         </select>
				 <font color="red"></font>
             </div>
             <div>
                 <label >是否付款：</label>
                 <input type="radio" name="ispayment" value="0" checked="checked">未付款
				 <input type="radio" name="ispayment" value="1" >已付款
             </div>
             <div class="providerAddBtn">
                  <input type="button" name="add" id="add" value="保存">
				  <input type="button" id="back" name="back" value="返回" >
             </div>
         </form>
     </div>
 </div>
</section>


<%@include file="../foot.jsp"%>